
let mixins = {
  data: function () {
    return {}
  },
  methods: {
    /**
     * bpm的请求封装，默认走pi
     * @param paramObj
     * @param succFunc
     * @param failFunc
     * @param reqFailFunc
     */
    /* let paramObj = {
        'tsId': '11111',
        'itCode': 'gyren',
        'lang': 'zh',
        'tsId': '-1',
        'apiName':'bpm1'
      } */
    httpBpm (paramObj, succFunc, failFunc) {
      httpBase(paramObj, data => {
        if (!data.data || !data.data.data) {
          console.error('返回数据格式错误', data)
          failFunc && failFunc(data, '请求失败')
          return
        }
        succFunc && succFunc(data.data.data)
      }, failFunc)
    },
    httpBpmFlow (paramObj, succFunc, failFunc, bizFailFunc) {
      this.httpBpm(paramObj, data => {
        console.log('httpBpmFlow return JSON', data)
        let respMessage = this.bpmcoreI18n.msgExecServiceError
        if (data.respCode && data.respMessage !== '') {
          respMessage = data.respMessage
        }
        // 异常码遍历
        if (data.respCode && data.respCode !== '200') {
          switch (data.respCode) {
            case '900000':
              this.alert(this.bpmcoreI18n.RESP_ERROR_900000)
              break
            case '900001':
              this.alert(this.bpmcoreI18n.RESP_ERROR_900001)
              break
            case '900002':
              this.alert(this.bpmcoreI18n.RESP_ERROR_900002)
              break
            case '900003':
              this.alert(this.bpmcoreI18n.RESP_ERROR_900003)
              break
            case '900004':
              this.alert(this.bpmcoreI18n.RESP_ERROR_900004)
              break
            case '900005':
              this.alert(this.bpmcoreI18n.RESP_ERROR_900005)
              break
            case '900006':
              this.alert(this.bpmcoreI18n.RESP_ERROR_900006)
              break
            case '910001':
              this.alert(this.bpmcoreI18n.RESP_ERROR_910001)
              break
            case '910002':
              this.alert(this.bpmcoreI18n.RESP_ERROR_910002)
              break
            case '910003':
              this.alert(this.bpmcoreI18n.RESP_ERROR_910003)
              break
            case '910004':
              this.alert(this.bpmcoreI18n.RESP_ERROR_910004)
              break
            case '910005':
              this.alert(this.bpmcoreI18n.RESP_ERROR_910005)
              break
            case '910006':
              this.alert(this.bpmcoreI18n.RESP_ERROR_910006)
              break
            case '910007':
              this.alert(this.bpmcoreI18n.RESP_ERROR_910007)
              break
            case '910008':
              this.alert(this.bpmcoreI18n.RESP_ERROR_910008)
              break
            case '910009':
              this.alert(this.bpmcoreI18n.RESP_ERROR_910009)
              break
            case '910010':
              this.alert(this.bpmcoreI18n.RESP_ERROR_910010)
              break
            case '910011':
              this.alert(respMessage)
              break
            case '910012':
              this.alert(respMessage)
              break
            case '910013':
              this.alert(respMessage)
              break
            case '910014':
              this.alert(this.bpmcoreI18n.RESP_ERROR_910014)
              break
            case '910015':
              this.alert(respMessage)
              break
            case '920001':
              this.alert(this.bpmcoreI18n.RESP_ERROR_920001)
              break
            case '920002':
              this.alert(this.bpmcoreI18n.RESP_ERROR_920002)
              break
            case '920003':
              this.alert(this.bpmcoreI18n.RESP_ERROR_920003)
              break
            case '920004':
              this.alert(respMessage)
              break
            case '920005':
              this.alert(this.bpmcoreI18n.RESP_ERROR_920005)
              break
            case '930001':
              this.alert(this.bpmcoreI18n.RESP_ERROR_930001)
              break
            case '930002':
              this.alert(this.bpmcoreI18n.RESP_ERROR_930002)
              break
            case '930003':
              this.alert(this.bpmcoreI18n.RESP_ERROR_930003)
              break
            case '930004':
              this.alert(respMessage)
              break
            case '930005':
              this.alert(this.bpmcoreI18n.RESP_ERROR_930005)
              break
            case '930006':
              this.alert(this.bpmcoreI18n.RESP_ERROR_930006)
              break
            case '940001':
              this.alert(this.bpmcoreI18n.RESP_ERROR_940001)
              break
            case '950001':
              this.alert(this.bpmcoreI18n.RESP_ERROR_950001)
              break
            case '9003':
              this.alert(this.bpmcoreI18n.RESP_ERROR_9003)
              break
            case '9004':
              this.alert(this.bpmcoreI18n.RESP_ERROR_9004)
              break
            case '9005':
              this.alert(this.bpmcoreI18n.RESP_ERROR_9005)
              break
            case '9006':
              this.alert(this.bpmcoreI18n.RESP_ERROR_9006)
              break
            case '9007':
              this.alert(this.bpmcoreI18n.RESP_ERROR_9007)
              break
            case '9008':
              this.alert(this.bpmcoreI18n.RESP_ERROR_9008)
              break
            case '9009':
              this.alert(this.bpmcoreI18n.RESP_ERROR_9009)
              break
            case '9010':
              this.alert(this.bpmcoreI18n.RESP_ERROR_9010)
              break
            case '9011':
              this.alert(respMessage)
              break
            default:
              this.alert(this.bpmcoreI18n.msgExecServiceError)
              break
          }
        }
        if (data.respCode && data.respCode !== '200') {
          bizFailFunc && bizFailFunc(data)
          return
        }
        succFunc && succFunc(data)
      }, data => {
        this.alert(this.bpmcoreI18n.msgExecServiceError)
        failFunc && failFunc(data)
      })
    },
    /**
     * 获取bpm的表数据通用方法
     * @param paramObj{tsPiid,tableName,dictFields,begin_line,page_LineNbr}
     * @param succFunc
     * @param failFunc
     */
    httpBpmGetBz (paramObj, succFunc, failFunc) {
      let searchClause = {
        sql: ' TS_ID=?',
        parameters: [paramObj.tsId]
      }
      this.httpBpm({
        inputParameter: JSON.stringify({
          'tableName': paramObj.tableName,
          'searchClause': JSON.stringify(searchClause),
          'dictFields': paramObj.dictFields,
          'begin_line': typeof paramObj.begin_line !== 'undefined' ? paramObj.begin_line : 0,
          'page_LineNbr': typeof paramObj.page_LineNbr !== 'undefined' ? paramObj.page_LineNbr : 10,
          'countFlag': typeof paramObj.countFlag !== 'undefined' ? paramObj.countFlag : 1
        }),
        async: paramObj.async,
        'apiName': 'EBCV_V3@AJAX_RetrieveProcessBzData'
      }, data => {
        if (data && data.returnCode === '000000') {
          let jsonResult = JSON.parse(data.jsonResult)
          console.log('调用EBCV_V3@AJAX_RetrieveProcessBzData的表【' + paramObj.tableName + '】的结果', jsonResult)
          succFunc && succFunc(jsonResult, data.totalNbr)
        } else {
          failFunc && failFunc('', '业务失败')
        }
      }, failFunc)
    },
    /**
     *
     * @param paramObj
     * @param succFunc
     * @param failFunc
     */

    httpBpmSaveBz (paramObj, succFunc, failFunc) {
      if (typeof paramObj.data.num !== 'undefined') {
        delete paramObj.data.num
      }
      this.httpBpm({
        inputParameter: JSON.stringify({
          'saveDataInputParameter': '',
          'tableName': paramObj.tableName,
          'keyFields': paramObj.keyFields,
          'saveFlag': typeof paramObj.saveFlag !== 'undefined' ? paramObj.saveFlag : '',
          'data': [paramObj.data]
        }),
        'apiName': 'EBCV_V3@AJAX_SaveProcessBzData'
      }, data => {
        if (data && data.returnCode === '000000') {
          succFunc && succFunc()
        } else {
          failFunc && failFunc('', '业务失败')
        }
      }, failFunc)
    },
    /**
     * 获取bpm的表数据通用方法
     * @param paramObj{tsPiid,tableName,dictFields,begin_line,page_LineNbr}
     * @param succFunc
     * @param failFunc
     */
    httpBpmDelBz (paramObj, succFunc, failFunc) {
      var sqlStr = '?'
      for (var i = 1; i < paramObj.mids.length; i++) {
        sqlStr += ',?'
      }
      console.log('45454545454')
      let delKey = 'mid'
      if (paramObj.delKey && paramObj.delKey !== null && paramObj.delKey !== '' && typeof paramObj.delKey !== 'undefined') {
        delKey = paramObj.delKey
      }
      let sql = ' ' + delKey + ' in (' + sqlStr + ')'
      var removeClause = {
        sql: sql,
        parameters: paramObj.mids
      }
      this.httpBpm({
        inputParameter: JSON.stringify({
          'tableName': paramObj.tableName,
          'removeClause': JSON.stringify(removeClause),
          'removeInputParameter': ''
        }),
        'apiName': 'EBCV_V3@AJAX_RemoveProcessBizData'
      }, data => {
        if (data && data.returnCode === '000000') {
          succFunc && succFunc()
        } else {
          failFunc && failFunc('', '业务失败')
        }
      }, failFunc)
    }
  }
}
export default mixins
